import java.util.*;


public class Solution6 {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * 
     * @param num int整型一维数组 
     * @return int整型ArrayList<ArrayList<>>
     */
    public ArrayList<ArrayList<Integer>> permuteUnique (int[] num) {
        // write code here
        Arrays.sort(num);
        ArrayList<ArrayList<Integer>> res = new ArrayList<>();
        fun(res,new ArrayList<Integer>(),num,new boolean[num.length]);
        return res;
    }
    void fun(ArrayList<ArrayList<Integer>> res,ArrayList<Integer> list,int[] num,boolean[] dp) {
        if(list.size() == num.length) {
            if(!res.contains(list)) {
                res.add(new ArrayList(list));
            }
        }
        for(int i = 0;i<num.length;i++) {
            if(!dp[i]) {
                list.add(num[i]);
                dp[i] = true;
                fun(res,list,num,dp);
                dp[i] = false;
                list.remove(list.size()-1);
            }
        }
    }
}